import Vue from 'vue';
import Router from 'vue-router';
import Login from '@/components/Login';
import Category from '@/components/Category';
import CategoryList from '@/components/CategoryList';
import Order from '@/components/Order';
import OrderList from '@/components/OrderList';
import Product from '@/components/Product';
import ProductList from '@/components/ProductList';

Vue.use(Router);
const router = new Router({
  routes: [{
    path: '/',
    name: 'Login',
    component: Login
  }, {
    path: '/category',
    name: 'Category',
    component: Category
  }, {
    path: '/categoryList',
    name: 'CategoryList',
    component: CategoryList
  }, {
    path: '/order',
    name: 'Order',
    component: Order
  }, {
    path: '/orderList',
    name: 'OrderList',
    component: OrderList
  }, {
    path: '/product',
    name: 'Product',
    component: Product
  }, {
    path: '/productList',
    name: 'ProductList',
    component: ProductList
  }]
});

router.beforeEach((to, from, next) => {
  const toDepth = to.path.split('/').length
  const fromDepth = from.path.split('/').length
  if (toDepth < fromDepth) {
    console.log('后退。。。')
    from.meta.keepAlive = false
    to.meta.keepAlive = true
  }
  next()
})


export default router
